﻿using System;
using System.Web;
using System.Web.SessionState;
using com.nm.library.Helper;

namespace com.nm.library {
    /// <summary>
    /// 存储当前会话的全局信息
    /// </summary>
    /// 
    public abstract class UserInfo
    {
        /// <summary>
        /// 
        /// </summary>
        protected static HttpSessionState Session => HttpContext.Current != null ? HttpContext.Current.Session : null;

        //public static string OpenID {
        //    get { return Session["OpenID"] as string; }
        //    set { Session["OpenID"] = value; }
        //}
        /// <summary>
        /// 用户ID.
        /// </summary>
        public static string UserID
        {
            get
            {
                return Session.Get("CurrentUserId",0).ToString();
                //return Session["UserID"] as string;
                
            }
            set
            {
                Session["UserID"] = value;
            }
        }

        /// <summary>
        /// 当前用户所属公司
        /// </summary>
        public static string UserCompanyId => Session.Get("CurrentUserCompanyId","");

        /// <summary>
        /// 当前用户所属公司的数据源
        /// </summary>
        public static string UserExtrSource => Session.Get("CurrentUserExtrSource", "");

        /// <summary>
        /// 当前用户角色
        /// </summary>
        public static bool RoleType => Session.Get("CurrentRoleType", false);

        public static int CusIDInt
        {
            get
            {
                try
                {
                    return (int)Session["CusIDInt"];
                }
                catch (Exception)
                {
                    return 0;
                }
            }
            set
            {
                Session["CusIDInt"] = value;
            }
        }
        public static bool OneClickTrade
        {
            get
            {
                return (bool)Session["OneClickTrade"];
            }
            set
            {
                Session["OneClickTrade"] = value;
            }
        }
        /// <summary>
        /// 是否测试用户
        /// </summary>
        public static bool IsTestUser
        {
            get
            {
                if (Session["IsTestUser"] == null)
                    return false;
                try
                {
                    return (bool)Session["IsTestUser"];
                }
                catch (Exception)
                {
                    return false;
                }
            }
            set
            {
                Session["IsTestUser"] = value;
            }
        }
        /// <summary>
        /// 登录名.
        /// </summary>
        public static string LoginAccount
        {
            get
            {
                return Session["LoginAccount"] as string;
            }
            set
            {
                Session["LoginAccount"] = value;
            }
        }

        /// <summary>
        /// 用户头像.
        /// </summary>
        public static string UserImg
        {
            get
            {
                return Session["UserImg"] as string;
            }
            set
            {
                Session["UserImg"] = value;
            }
        }

        /// <summary>
        /// 用户名称.
        /// </summary>
        public static string UserName
        {
            get
            {
                return Session["UserName"] as string;
            }
            set
            {
                Session["UserName"] = value;
            }
        }
        /// <summary>
        /// 用户等级.
        /// </summary>
        public static string CusType
        {
            get
            {
                return Session["CusType"] as string;
            }
            set
            {
                Session["CusType"] = value;
            }
        }

        /// <summary>
        /// 用户类型.company,person,admin
        /// </summary>
        public static string UserType
        {
            get
            {
                return Session["UserType"] as string;
            }
            set
            {
                Session["UserType"] = value;
            }
        }

        /// <summary>
        /// 当前用户所属的部门
        /// </summary>
        public static string DeptNo
        {
            get
            {
                return Session["DeptNo"] as string;
            }
            set
            {
                Session["DeptNo"] = value;
            }
        }

        public static string AnonymousId
        {
            get { return Session["AnonymousId"] as string; }
            set { Session["AnonymousId"] = value; }
        }
    }
}
